// http://localhost:8000
const baseUrl = "/exam";

/**
 * 禁用部分浏览器操作
 */
function disableSomeCtrl() {
    window.document.onkeydown = (e) => {
        if((e.ctrlKey || e.metaKey) && e.key.toUpperCase() == "C") {
            // Ctrl/Command + C
            e.preventDefault();
            return false;
        }
        if((e.ctrlKey || e.metaKey) && e.key.toUpperCase() == "V") {
            // Ctrl/Command + V
            e.preventDefault();
            return false;
        }
        //console.log(e);
        return true;
    };
    // 禁止右键
    window.document.oncontextmenu = function (e) {
        e.preventDefault();
        e.returnValue = false;
    };
}

(function f(global) {
    let fullObj = { };

    /**
     * 默认使用 html 标签
     * @param element 准备全屏的元素, 可以省略, 省略时, 第一个参数就是 callback
     * @param callback fullscreenchange 时调用, 也可以省略
     */
    fullObj.init = function (element, callback) {
        if(typeof element == 'function') {
            callback = element;
            element = undefined;
        }
        if(element) {
            fullObj.root = element;
        } else {
            fullObj.root = document.documentElement;
            if(!fullObj.root) {
                fullObj.root = document.getElementsByTagName("html")[0];
            }
        }

        fullObj.callback = callback;
        fullObj.root.fullscreenEnabled = true;
        fullObj.root.onfullscreenchange = () => {
            // callback 的 内的 this改为 fullObj
            fullObj.callback.call(fullObj);
        };
    };

    fullObj.isFullScreen = function(){
        let fullEle = document.fullscreenElement;
        return fullEle ? true : false;
    };

    fullObj.doFullScreen = function () {
        if(fullObj.isFullScreen()) {
            return;
        }
        fullObj.root.requestFullscreen().catch((err) => {
            console.log('无法进入全屏, 请联系管理员:', err);
        });
    };
    fullObj.doExitScreen = function () {
        document.exitFullscreen().catch((err) => {
            console.log('无法退出全屏, 请联系管理员:', err);
        });
    };

    global.fullObj = fullObj;
})(window);